"""devops_api URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include,re_path
from django.views.static import serve
from devops_api import settings

from libs.token_auth import CustomAuthToken,ChangeUserPasswordView,ChangeUserInfoView
from cmdb.views import HostCollectView,CreateHostView,ExcelCreateHostView,AliyunCloudView,TencentCloudView
from app_release.views import DeployView, RollbackView, ApplyEchartView, GitBranchView, ReleaseResultView

from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='接口文档')

from user.views import CleanLoginLogsView,VisitEchartView
from libs.avatar import UploadAvatarView
from cron.views import EnableView,DjangoCronjobView,DeletRecordView
from batch.views import CommandView,ServerUploadView,CommandEchartView,DeleteExecutionRecordView
from libs.secret import RandomPasswordView
from system_config.views import BlacklistView
from tools.views import RemindEnableView,FaultDownFile

urlpatterns = [
    path('admin/', admin.site.urls),
    # 配置媒体文件的路由地址
    re_path('^media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT},name='media'),
    re_path('^api/docs/$', schema_view),
    re_path('^api/login/$', CustomAuthToken.as_view()),
    re_path('^api/change_password/$', ChangeUserPasswordView.as_view()),
    re_path('^api/cmdb/host_collect/$', HostCollectView.as_view()),
    re_path('^api/cmdb/create_host/$', CreateHostView.as_view()),
    re_path('^api/cmdb/excel_create_host/$', ExcelCreateHostView.as_view()),
    re_path('^api/cmdb/aliyun_cloud/$', AliyunCloudView.as_view()),
    re_path('^api/cmdb/tencent_cloud/$', TencentCloudView.as_view()),
    re_path('^api/app_release/git_branch/$', GitBranchView.as_view()),
    re_path('^api/app_release/deploy/$', DeployView.as_view()),
    re_path('^api/app_release/rollback/$', RollbackView.as_view()),
    re_path('^api/app_release/release_result/$', ReleaseResultView.as_view()),
    re_path('^api/app_release/apply_echart/$', ApplyEchartView.as_view()),
    re_path('^api/change_userinfo/$', ChangeUserInfoView.as_view()),
    re_path('^api/user_avatar_upload/$', UploadAvatarView.as_view()),
    re_path('^api/cron_enable/$', EnableView.as_view()),
    re_path('^api/batch_command/$', CommandView.as_view()),
    re_path('^api/batch_file/$', ServerUploadView.as_view()),
    re_path('^api/random_password/$', RandomPasswordView.as_view()),
    re_path('^api/clean_log/$', CleanLoginLogsView.as_view()),
    re_path('^api/command_echart/$', CommandEchartView.as_view()),
    re_path('^api/visit_echart/$', VisitEchartView.as_view()),
    re_path('^api/blacklist/$', BlacklistView.as_view()),
    re_path('^api/remind_enable/$', RemindEnableView.as_view()),
    re_path('^api/scheduler_job/$', DjangoCronjobView.as_view()),
    re_path('^api/delete_record/$', DeletRecordView.as_view()),
    re_path('^api/delete_executionrecord/$', DeleteExecutionRecordView.as_view()),
    re_path('^api/fault_down_file/$', FaultDownFile.as_view()),
]

#cmdb系统
from cmdb.views import IdcViewSet, ServerGroupViewSet, ServerViewSet
from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'cmdb/idc', IdcViewSet, basename="idc")
router.register(r'cmdb/server_group', ServerGroupViewSet, basename="server_group")
router.register(r'cmdb/server', ServerViewSet, basename="server")

#应用发布
from app_release.views import EnvViewSet, ProjectViewSet, AppViewSet, ReleaseConfigViewSet, ReleaseApplyViewSet
router.register(r'app_release/env', EnvViewSet, basename="env")
router.register(r'app_release/project', ProjectViewSet, basename="project")
router.register(r'app_release/app', AppViewSet, basename="app")
router.register(r'app_release/config', ReleaseConfigViewSet, basename="config")
# router.register(r'app_release/apply', ReleaseApplyViewSet, basename="apply")

#系统配置
from system_config.views import CredentialViewSet,NotifyViewSet
router.register(r'config/credential', CredentialViewSet, basename="credential")
router.register(r'config/notify', NotifyViewSet, basename="notify")

#用户管理
from user.views import UserViewSet,UserlogViewSet,OperatelogViewSet
router.register(r'config/user', UserViewSet, basename="user")
router.register(r'config/userlog', UserlogViewSet, basename="userlog")
router.register(r'config/operatelog', OperatelogViewSet, basename="operatelog")

#任务管理
from cron.views import CronJobViewSet,DjangoCronjobViewSet,DjangoJobExecutionViewSet
router.register(r'task/cron', CronJobViewSet, basename="cron")
router.register(r'task/scheduler', DjangoCronjobViewSet, basename="scheduler")
router.register(r'task/record', DjangoJobExecutionViewSet, basename="record")

#运维工具管理
from tools.views import EventViewSet,FaultViewSet,RemindViewSet
router.register(r'tools/event', EventViewSet, basename="event")
router.register(r'tools/fault', FaultViewSet, basename="fault")
router.register(r'tools/remind', RemindViewSet, basename="remind")

#批量执行
from batch.views import ExecutionRecordViewSet
router.register(r'batch/execution_record', ExecutionRecordViewSet, basename="execution_record")

urlpatterns += [
    path('api/', include(router.urls))
]



